package com.example.mapper;

import com.example.entity.Scientific;
import com.example.entity.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ScientificMapper {

    // 根据ID查询科研成果
    @Select("select * from scientific where id = #{id}")
    Scientific selectById(Integer id);

    // 插入科研成果
    @Insert("insert into scientific values (null,#{name},#{level},#{dept},#{rewardLevel},#{rewardCategory},#{rewardList},#{rewardDate},#{materials},#{cartUrl},#{declarationDate},#{state},#{reason},#{stuId},now())")
    void insert(Scientific scientific);

    // 根据ID更新科研成果信息
    @Update("<script> " + "update scientific " + "<set> " + "<if test='name != null'> " + "name = #{name}, " + "</if> " + "<if test='rewardCategory != null'> " + "reward_category = #{rewardCategory}, " + "</if> " + "<if test='rewardList != null'> " + "reward_list = #{rewardList}, " + "</if> " + "<if test='rewardLevel != null'>" + "reward_level = #{rewardLevel}, " + "</if>" + "<if test='declarationDate != null'> " + "declaration_date = #{declarationDate}, " + "</if> " + "<if test='rewardDate != null'> " + "reward_date = #{rewardDate}, " + "</if> " + "<if test='dept != null'> " + "dept = #{dept}, " + "</if> " + "<if test='level != null'> " + "level= #{level}, " + "</if> " + "<if test='materials != null'> " + "materials = #{materials}, " + "</if> " + "<if test='cartUrl != null'> " + "cart_url = #{cartUrl}, " + "</if> " + "<if test='state != null'> " + "state = #{state}, " + "</if> " + "<if test='reason != null'> " + "reason = #{reason} " + "</if> " + "</set>" + "where id=#{id}" + "</script>")
    void updateById(Scientific scientific);

    // 根据ID删除科研成果
    @Delete("delete from scientific where id= #{id}")
    void deleteById(Integer id);

    // 根据条件查询科研成果列表
    @Select("<script>" + "select * from scientific <where> " + "<if test='name !=null'> " + "name like concat('%',#{name},'%') " + "</if> " + "<if test='rewardCategory !=null'> " + "and reward_category like concat('%',#{rewardCategory},'%') " + "</if> " + "<if test='state !=null'> " + "and state = #{state} " + "</if> " + "<if test='stuId !=null'> " + "and stu_id = #{stuId} " + "</if> " + "<if test='createTime !=null'> " + "and create_time &gt;= '${createTime} 00:00:00' and create_time &lt;= '${createTime} 23:59:59'" + "</if> " + "</where> " + "</script>")
    List<Scientific> selectAll(Scientific scientific);
}
